package boot

import (
	"fmt"
	"github.com/nsqio/go-nsq"
	"log"
)

// 框架需要的队列初始化配置
func init() {
	fmt.Println("=========初始化队列end========")
	initNewConsumer()
	fmt.Println("=========初始化队列end========")
}

var address = "127.0.0.1:4161"

func testTopic(message *nsq.Message) error {
	log.Printf("消费test2Topic: %s", message.Body)
	return nil
}
func test2Topic(message *nsq.Message) error {
	log.Printf("消费test1Topic: %s", message.Body)
	return nil
}
func initNewConsumer() {
	config := nsq.NewConfig()
	c, _ := nsq.NewConsumer("testTopic", "ch", config)
	c2, _ := nsq.NewConsumer("test2Topic", "ch", config)
	c2.AddHandler(nsq.HandlerFunc(test2Topic))
	c.AddHandler(nsq.HandlerFunc(testTopic))
	// 1.直连nsqd
	// err := c.ConnectToNSQD("127.0.0.1:4150")
	// 2.通过 nsqlookupd 服务发现
	_ = c.ConnectToNSQLookupd(address)
	_ = c2.ConnectToNSQLookupd(address)

}
